Repository navigation
CKS: report drift between a cluster's VM map, its VMs and its Kubernetes nodes - #14666
bhouse-nexthop wants to merge 1 commit into
Conversation
…tes nodes Scale, upgrade, stop/start and the status scanner trust kubernetes_cluster_vm_map as the list of a cluster's VMs, but nothing checks it. When it drifts from reality, after a node rebuilt by hand, a database edit or a failed destroy on scale-down, the cluster sits in Alert or runs a node CloudStack does not know about, and nobody is told which VM or node is the cause. Every 5 minutes, the status scanner now starts a check, on its own thread, of each CloudManaged cluster in Running or Alert state. It compares the map with the cluster's VMs in CloudStack, matched by the cluster's node name prefix and owner, and, over SSH with kubectl as the other operations do, with its Kubernetes nodes. It reports mapped VMs that are destroyed, expunged, in Error or missing; VMs named as nodes of the cluster but not mapped; Kubernetes nodes with no VM; and mapped running VMs that are not nodes, after a 15 minute grace period. If kubectl cannot be run, only the VMs are compared. Each mismatch raises a WARN event and an alert naming the cluster and the VM or node, once. The mismatches reported are kept in cluster details, so a mismatch is only reported again once it has gone and come back, and an INFO event says when the cluster matches again. Clusters changing state or map during the check are not reported. Nothing is changed. The check can be turned off with cloud.kubernetes.cluster.vm.map.check.enabled. Signed-off-by: Brad House <bhouse@nexthop.ai>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.22 #14666 +/- ##
============================================
+ Coverage 18.32% 18.35% +0.03%
- Complexity 16644 16723 +79
============================================
Files 5939 5941 +2
Lines 537787 538107 +320
Branches 65932 65980 +48
============================================
+ Hits 98544 98780 +236
- Misses 428033 428112 +79
- Partials 11210 11215 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Test report: VM map drift check (commit 0963c36)Summary: the check runs every 5 minutes on its own thread and covers every CloudManaged cluster in Running or Alert state. Three existing clusters gave no findings over three cycles. On a fresh test cluster, each kind of drift I caused was reported once, with one WARN event and one alert naming the VM, and wasn't reported again on later cycles. Once I undid it, the next cycle recorded the INFO "matches ... again" event and removed the detail. The kinds covered were a missing map row, a map row for an expunged VM, a map row for a VM that doesn't exist, a running node VM that isn't a Kubernetes node, and a stray VM named as a node. When SSH to the control node failed, only the VM comparison ran: the node finding was kept, neither cleared nor reported again, and it cleared once SSH was back. With the setting off nothing ran. A cluster in the middle of a real scale-up was skipped. The check changed nothing, and the management-server log had no exceptions or NPEs from it. Environment
Results
How the drift was caused
1: baseline
2: missing map row
3: stale map rows
4: running VM that isn't a node
5: SSH failure
6: setting off
7: cluster mid-operation
8: no changes
Logs
Not covered
Result: pass. The check reports each kind of drift once with an event and an alert, records the INFO event when the drift is undone, and keeps the node findings when kubectl can't be reached. It is off when the setting is false and skips clusters that are being operated on. It changed nothing, and the three existing clusters gave no false findings. |
Description
This PR adds a check that
kubernetes_cluster_vm_mapstill matches the cluster it describes. Detection only: the map, the VMs and the cluster are left as they are.Fixes #14665
What it checks
Every 5 minutes the Kubernetes cluster status scanner starts a check on its own thread, so the scanner and its lock are not held up by SSH. The check runs under its own global lock, so only one management server checks at a time. For each CloudManaged cluster in Running or Alert state it compares three views:
<prefix>-control-<hex>,<prefix>-node-<hex>,<etcd prefix>-<n>-<hex>, including the 40-character prefix used before Normalize naming of Kubernetes clusters #10778), with their state;kubectl get nodes -o nameon the control node, over SSH in the same way the other operations do.It reports:
If kubectl can't be run (no SSH address, SSH or kubectl failing), only the map is compared with the VMs. What was found on the nodes before is kept, neither cleared nor reported again.
Clusters in any other state (Starting, Scaling, Upgrading, Stopping, RemovingNodes, ...) and ExternalManaged clusters are skipped. The cluster's state and map are read again before reporting, and nothing is reported if either changed during the check, for example because an operation ran meanwhile.
Alerts and dedupe
Each mismatch raises a WARN event (
KUBERNETES.CLUSTER.VM.MAP.CHECK, on the cluster, not displayed to end users) and an alert naming the cluster and the VM or node. The alert type isALERT_TYPE_USERVM, an existing type, so 4.22 gets no new alert type. Each alert is a separate alert.The keys of the mismatches reported are kept in two cluster details (
vmMapCheckReportedVmDrift,vmMapCheckReportedNodeDrift, not displayed), so the dedupe also holds across restarts and management servers:The details are written before the alerts are sent. More than 5 new mismatches in one cluster at once give 5 alerts and one summing up the rest, and each mismatch still gets its event.
Setting
cloud.kubernetes.cluster.vm.map.check.enabled(global, dynamic, defaulttrue) turns the check off. No schema change.Notes
The API and UI already refuse to destroy a VM of a CKS cluster. The path through which a failed destroy on scale-down left the map behind is fixed in #14611. What is left is drift from manual node rebuilds and database edits, which this reports.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
How Has This Been Tested?
Unit tests,
KubernetesClusterVmMapCheckerTest(32) andKubernetesClusterVmMapCheckWorkerTest(8), cover:All
Kubernetes*Testtests in the plugin pass.